package com.example.homework.activity;

import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.homework.R;
import com.example.homework.goodsListAdapter;
import com.example.homework.utils.DataMaker;
import com.example.homework.utils.GoodInfo;

import java.util.ArrayList;
import java.util.List;


/**
 * 完成产品列表功能
 */
public class ProductListActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private LinearLayoutManager linearLayoutManager;

    // private List<Good> goodList = new ArrayList<Good>();
    private List<GoodInfo> goodList = new ArrayList<GoodInfo>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_product_list);
        initView();
    }


    private void initView() {

//        for (int i = 0; i < 10; i++) {
//            Good good = new Good();
//            good.setImage(pictrue[i]);
//            good.setName(title[i]);
//            good.setProductLocation(location[i]);
//            good.setShopName(shop[i]);
//            good.setPrice(Double.valueOf(prices[i]));
//            good.setVolume(number[i]);
//            goodList.add(good);
//        }
        goodList= DataMaker.makeGoodList();


        recyclerView = (RecyclerView) findViewById(R.id.recylerViews);
        linearLayoutManager = new LinearLayoutManager(this);
        //   LinearLayoutManager linearLayoutManager = new LinearLayoutManager(RecyclerViewSampleActivity.this);

        recyclerView.setLayoutManager(linearLayoutManager);
        //为recycleViews设定动画
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        //为recycleViews添加分割线
        recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration
                .VERTICAL));
        recyclerView.setAdapter(new goodsListAdapter(this, goodList));
    }
}